#include "io_thread_pool.h"
#include <cstdint>

IOThreadPool::IOThreadPool(uint32_t threadNum)
:m_work(new boost::asio::io_service::work(m_ctx))
{
    for(uint32_t i = 0; i < threadNum; ++i)
    {
        m_threads.emplace_back([this](){
            m_ctx.run();
        });
    }
}

IOThreadPool::IOContext& IOThreadPool::GetIOContext()
{
    return m_ctx;
}

void IOThreadPool::Stop()
{
    m_work.reset();
    m_ctx.stop();
    for(auto& t : m_threads)
    {
        t.join();
    }
}

IOThreadPool::~IOThreadPool()
{
    Stop();
}
